#! /usr/bin/env python3
# coding=utf-8

"""
Fetch the access_token and then print it

2019-3-23 by Stone at GDOU-KC
"""
import sys
import logging
import json
import requests

logging.basicConfig(level=logging.DEBUG)
debug_where = lambda msg, *args, **kw: logging.debug("@%s | " % __name__ + msg, *args, **kw)

# ===== ===== ===== ===== =====
# Constants
# ===== ===== ===== ===== =====
# the url to request access_token
URL = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={app_id}&secret={app_secret}'


# ===== ===== ==== ===== =====
# main
# ==== ===== ===== ===== =====
if __name__ == '__main__':
    try:
        debug_where("argv: %s" % sys.argv)
        app_id = sys.argv[1]
        app_secret = sys.argv[2]
    except IndexError:
        print("app_id and app_secret should be passed as parameter. Script exited!")
        sys.exit()

    # debug_where("access_token: %s" % access_token)
    url = URL.format(app_id=app_id, app_secret=app_secret)

    debug_where("url: %s" % url)

    reqt = requests.post(url)
    print("response: %s" % reqt.content)





